Skip to content

Phase 4: Agent context, doctor, CLAUDE.md, README - #4

Closed
padak wants to merge 1 commit into
mainfrom
phase-4-context-doctor
Closed

Phase 4: Agent context, doctor, CLAUDE.md, README#4
padak wants to merge 1 commit into
mainfrom
phase-4-context-doctor

Conversation

@padak

@padak padak commented Feb 26, 2026

Copy link
Copy Markdown
Member

Implementation Summary

Full implementation of Phase 4: kbagent context command with comprehensive AI agent instructions, kbagent doctor health check command with 4 diagnostic checks, CLAUDE.md project development context, and complete README.md documentation.

What was implemented

src/keboola_agent_cli/commands/context.py -- Complete agent instructions including:

  • What kbagent is and who it is for
  • All commands with copy-pasteable examples (project add/list/remove/edit/status, config list/detail, doctor, context)
  • Global flags table (--json, --verbose, --no-color)
  • JSON output format documentation (success/error envelopes)
  • Exit codes table (0-5)
  • Common workflows (setup, explore configs, verify, multi-project)
  • Tips for AI agents (7 actionable tips)
  • Environment variables documentation (KBC_TOKEN, KBC_STORAGE_API_URL)

src/keboola_agent_cli/commands/doctor.py -- Health check with 4 checks:

  • Check 1: Config file existence and permissions (0600)
  • Check 2: Config file validity (valid JSON, parseable, version check)
  • Check 3: Project connectivity (token verification via API with response time for each project)
  • Check 4: CLI version
  • Rich panel output in human mode, structured JSON in --json mode

CLAUDE.md -- Project development context with:

  • Build/run/test instructions
  • Project structure overview
  • 3-layer architecture explanation
  • Coding conventions (commands, services, models, output, error handling, testing)

README.md -- Complete user-facing documentation with:

  • Installation (uv, pip, dev mode)
  • Quick start guide
  • All commands documented in tables
  • JSON output format
  • Exit codes
  • Environment variables
  • Architecture overview

Acceptance Criteria

  • kbagent context outputs comprehensive usage instructions
  • kbagent context mentions --json, exit codes, workflows
  • kbagent doctor checks config file existence, permissions, validity
  • kbagent doctor tests connectivity to all projects
  • kbagent doctor --json outputs structured JSON
  • CLAUDE.md exists with build/run/test instructions
  • README.md exists with installation and all commands
  • All exit codes consistent
  • --no-color works correctly

Tests

  • uv run pytest tests/ -v -- 133 passed (114 existing + 19 new)

New test classes added to tests/test_cli.py:

  • TestContextCommand (4 tests): key phrases, JSON mode, exit codes table, environment variables
  • TestDoctorCommand (7 tests): no config, config with projects, permissions check, connectivity check, CLI version, human mode panel, invalid config JSON
  • TestNoColorFlag (4 tests): help, project list, context, doctor
  • TestExitCodes (4 tests): auth error (3), network error (4), config error (5), connection error (4)

Files Changed

  • src/keboola_agent_cli/commands/context.py -- replaced stub with full agent instructions
  • src/keboola_agent_cli/commands/doctor.py -- replaced stub with full health check
  • CLAUDE.md -- new file, project development context
  • README.md -- replaced minimal README with full documentation
  • tests/test_cli.py -- added 19 new tests (4 test classes)

🤖 Generated with Claude Code

Implement the full `kbagent context` command with comprehensive AI agent
instructions (all commands with examples, --json tips, exit codes table,
workflows, environment variables).

Implement `kbagent doctor` health check with four checks:
- Config file existence and permissions (0600)
- Config file validity (valid JSON, parseable)
- Project connectivity (token verification with response time)
- CLI version

Add CLAUDE.md with build/run/test instructions and coding conventions.
Replace minimal README.md with full documentation including installation,
quick start, all commands, architecture overview.

Add 19 new tests covering context output, doctor checks, --no-color flag,
and exit codes (3=auth, 4=network, 5=config).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@padak padak closed this Feb 26, 2026
martinsifra added a commit that referenced this pull request Aug 26, 2026
The big one (#2, upgraded): the diff sides' wire shape was WRONG in the
implementation and in the test fixtures that defined it. Verified against
connection (ConfigurationVersionResponse + ConfigurationDiffData OA
schemas, now recorded in the notes wire-truth table): each side is
{version, isDeleted, diff: {name, description, changeDescription,
isDisabled, configuration, rows}} -- content NESTED under diff,
version/deletion as side metadata. The classification and both take modes
now read the envelope; the flat-side code would have been dead on arrival
against the live API.

#1: resolve_conflict no longer takes branch_id -- it derives the branch
from the MR itself (branches.branchFromId), so the conflict-set guard and
the branch being written to can never disagree; a caller-supplied id could
point the REPLACing rebase at an unrelated dev branch the guard never
checked. A published/canceled MR (null branchFromId) is refused readably.

#3: take=theirs of a deleted side collapses to the delete resolution,
symmetric with ours ('production deleted it, dev changed it' is a live
conflict shape).
#4: deletion surfaces as top-level ours_deleted/theirs_deleted booleans on
get_config_diff (None = side never existed) -- it is side metadata, not a
content path.
#5: a 'both' row where the sides agree on the identical value carries
agreed: true -- agreement, not a conflict hotspot.
#2 (message half): a take side missing required envelope keys is reported
as a backend contract violation pointing at the resolved-body workaround,
not as caller error.
#6: wire ids compared via _same_id / int-coerced (find_merge_request_for_
branch, merge()'s was_active) -- a string-serialized branchFromId can no
longer silently defeat the post-merge cleanup.
#7: the feature pre-flight raises FeatureNotEnabledError carrying the new
ErrorCode.FEATURE_NOT_ENABLED (value matches the string SearchService
already emits; categorized 'configuration' like PAYG_NOT_AVAILABLE).
#8: ConfigError imported from ..errors like every other service; the
isDefault scan hoisted to services.base.find_default_branch_id and the
copies in config/sync/workspace services migrated (lib.py keeps its own
loop -- the SDK facade does not import the services layer); verify_token
is skipped when the server already serialized viewer (the polyfill's cost
dies with the polyfill); list --state validates against the closed
vocabulary instead of returning a silent count: 0 on a typo.
#9: test imports hoisted (no mid-file noqa), mocks spec'd at the L3 seam
(KeboolaClient + MergeRequests -- a renamed L3 method now fails the tests),
and regression tests added for every finding (82 tests total).

Doc drift: layer2/layer3 references updated to BRANCHES_MERGE_REQUESTS_
FEATURE, the layer3 open nit closed, tokens.py line ref fixed.

Review: tasks/pr-703-review.md (2026-08-27).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
martinsifra added a commit that referenced this pull request Aug 27, 2026
…actions, derive_state honesty [DMD-1899]

Adversarial review of every wire assumption against Connection source
(tasks/pr-703-opus-wire-review.md): 7 CONFIRMED, 3 MISMATCH. The fixes:

409 mapping (finding #4): the conflict 409 is NOT code-less -- an earlier
reading missed ExceptionConverter, which serializes
MergeValidationException's own string code storage.mergeRequests.validation
top-level as `code`, plus the conflicting configurations in
`params.errors`. _remap_merge_conflict now matches BOTH codes explicitly
(code-less 409 falls back to conflict for older stacks; a 409 with any
OTHER code passes through unmapped instead of being confidently mislabeled
a conflict), and http_base surfaces `params` as
details.api_error_params so the conflict list travels with the error
instead of demanding a second round trip. Stale 'carries no code' claims
corrected in errors.py, the L3 docstring, error-codes.md, the notes
wire-truth table and the RFC.

allowed_actions (finding #7): `approve` removed from the `approved`
tuple -- the transition's sole `from` place is in_review; from approved
the backend answers 422 (the UI button offering it there is wrong).
`update` added to in_merge (the server blocks update only in terminal
states). Docstring records the AddApprovalGuard gating and that with the
non-SOX default of 0 required approvals, approve is 422 in every state and
in_review itself is unreachable.

derive_state honesty (finding #10, the significant one): reviewers[].status
is populated only within a review round anchored by a review_requested
activity event -- which skip_review never writes -- and explicit reviewers
shadow every non-reviewer's decision (the creator can never BE a reviewer).
So in a default non-SOX project the rejected / self-closed derivations
never fire; the UI badge has the identical blind spot, since our table is
its port. Documented in the docstring and the RFC rather than re-derived
from the activity log client-side: the reliable fix is server-side
(commented on DMD-1988 -- derive from the activity log, not reviewers[]).

Sharp edges from confirmed items: a take side with a null/empty `name`
(nullable in the diff envelope, required non-empty by the rebase validator)
is refused as a contract violation instead of sailing into a server 400;
_branch_from_id_of documents that its null check is racy (branchFromId is
nulled by the FK when the async branch delete lands, not by the state
change); the viewer docstring notes detail/conflicts require an admin token
anyway (MergeRequestVoter).

Regression tests for each fix; 87 service tests total.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant